package com.zzu.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.zzu.view.fragment.ExpressInfoFragment;
import com.zzu.view.fragment.MapFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: bytedance
 * @date: 2021-05-09 17:50
 */
public class ViewpagerStateAdapter extends FragmentStateAdapter {

    //传入当前的包裹单号
    String packageId = "1234567891234";//默认的fragment
    String nowAddress = "河南省郑州市中原区";
    public ViewpagerStateAdapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle,String packageId,String nowAddress) {
        super(fragmentManager, lifecycle);
        this.packageId = packageId;
        this.nowAddress = nowAddress;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        if(position == 0){
            //返回显示详细信息的fragment
            return ExpressInfoFragment.newInstance(packageId,nowAddress);
        }else{
            //返回显示地图的fragment
            return MapFragment.newInstance(packageId);
        }

    }



    //一共有两个fragment
    @Override
    public int getItemCount() {
        return 2;
    }
}
